package net.lab1024.sa.admin.module.business.supercomputer.sqlgenerator.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import net.lab1024.sa.admin.module.business.supercomputer.sqlgenerator.domain.vo.SqlTextVO;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.constant.SwaggerTagConst;
import net.lab1024.sa.admin.module.business.supercomputer.sqlgenerator.service.SqlGeneratorService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;

@Tag(name = SwaggerTagConst.Support.SQL_GENERATOR)
@Controller
public class SqlGeneratorController {

    //TODO:SQL生成代码业务开发
    @Resource
    SqlGeneratorService sqlGeneratorService;

    @Operation(summary = "获取Source和Sink端的SQL语句")
    @GetMapping("/getCode/getSqlString")
    @SaCheckPermission("getCode:getSqlString")
    @ResponseBody
    public ResponseDTO<SqlTextVO> getSqlString(@RequestParam Integer taskId) throws IOException {
        return ResponseDTO.ok(sqlGeneratorService.getSQL(taskId));
    }

    @Operation(summary = "获取Source和Sink端的SQL语句,用于浏览")
    @GetMapping("/getCode/preview")
    @SaCheckPermission("getCode:preview")
    @ResponseBody
    public ResponseDTO<SqlTextVO> preview(@RequestParam Integer taskId) throws IOException {
        return ResponseDTO.ok(sqlGeneratorService.getSQL(taskId));
    }
}
